package ws

import (
	"go-stage/core"
	"net"

	"google.golang.org/grpc"
)

type Ws struct {
	Address              string
	RegisterServiceFuncs []func(s *grpc.Server)
}

func (w *Ws) Run() {
	listen, err := net.Listen("tcp", w.Address)
	if err != nil {
		core.Log.Errorf("failed to listen: %v", err)
		return
	}
	s := grpc.NewServer()
	for _, f := range w.RegisterServiceFuncs {
		f(s)
	}

	core.Log.Infof("Listen on %s", w.Address)
	s.Serve(listen)
}

type Cs struct {
	Name    string
	Address string
}
